"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var menu_1 = require("../menu");
var MenuComponent = /** @class */ (function () {
    function MenuComponent(menuService, _router) {
        this.menuService = menuService;
        this._router = _router;
        this.menus = [];
        this.currentItems = {
            expanded: '',
            title: '',
            children: ''
        };
        this.menus = menu_1.PAGES_MENU;
        /*setInterval(() => {
         console.log('aaa');
         console.log(this.menuService.menus);
         }, 1000);*/
    }
    MenuComponent.prototype.ngAfterViewInit = function () {
        /*this.menus = this.menuService.menus;
         console.log(this.menuService.menus);
         console.log('存在');
         this.updateMenu(this._router.url);*/
        // console.log(this.menus);
    };
    MenuComponent.prototype.ngOnInit = function () {
        var _this = this;
        // rel
        if (!this.menuService.menus) {
            this.menuService.eventbus.subscribe(function (_event) {
                if (_event.type === 2) {
                    _this.menuService.updateMenu(_event.url);
                    _this.menus = _event.url;
                    _this.updateMenu(_this._router.url);
                    _this.menuService.eventbus.emit({
                        type: 1,
                        url: _this._router.url
                    });
                }
            });
        }
        else {
            this.menus = this.menuService.menus;
            this.updateMenu(this._router.url);
        }
        /*this.menus = PAGES_MENU;
         this.updateMenu(this.menus);*/
        /*if (!this.menuService.menus) {
         this.menuService.getMenu().subscribe(res => {
         this.menuService.updateMenu(res.data);
         console.log(res.data);
         this.menus = this.menuService.menus;
         this.updateMenu(this._router.url);
         this.menuService.eventbus.emit({
         type: 1,
         url: this._router.url
         });
         });
         console.log('加载');
         } else {
         this.menus = this.menuService.menus;
         console.log('存在');
         this.updateMenu(this._router.url);
         }*/
        /*this.menus = this.menuService.menus;
         console.log(this.menuService.menus);
         this.updateMenu(this._router.url);*/
        // console.log(this.menus);
        // console.log(this.menuService.menus);
        // this.menuItems = this.menuService.menuItems;
        // this._router.isActive()
        // this.updateMenu(this._router.url);
        // this.toggleChildren(this._router.url);
        // console.log('this.currentItems');
        // console.log(this.currentItems);
    };
    MenuComponent.prototype.toggle = function (path) {
        this.updateMenu(path);
    };
    MenuComponent.prototype.toggleChildren = function (path) {
        var _this = this;
        // console.log('toggleChildren');
        // console.log(path);
        var arrUrl = path.split('/');
        // console.log(arrUrl);
        this.menus.forEach(function (items) {
            items.forEach(function (item) {
                // item.data.menu.expanded = false;
                // item.data.menu.selected = false;
                if (arrUrl[1] + '/' + arrUrl[2] === item.path) {
                    // item.data.menu.expanded = true;
                    // item.data.menu.selected = true;
                    // console.log(item);
                    item.children.forEach(function (ite) {
                        if (arrUrl[3] === ite.path) {
                            if (ite.expanded === 'true') {
                                ite.expanded = 'false';
                            }
                            else {
                                ite.expanded = 'true';
                            }
                            // ite.data.menu.expanded = !(ite.data.menu.expanded);
                            // ite.data.menu.selected = !(ite.data.menu.selected);
                        }
                    });
                    _this.currentItems = item;
                    /*item.data.menu.expanded = true;
                     item.data.menu.selected = true;
                     this.currentItems = item;*/
                }
            });
        });
        // console.log(this.menus);
    };
    MenuComponent.prototype.updateMenu = function (path) {
        var _this = this;
        var arrUrl = path.split('/');
        this.menus.forEach(function (value) {
            // 广告＼营销
            value.forEach(function (value1) {
                value1.selected = 'false';
                if (arrUrl[1] + '/' + arrUrl[2] === value1.path) {
                    value1.selected = 'true';
                    _this.currentItems = value1;
                    if (value1.expanded === 'false') {
                        _this._router.navigate([path]);
                    }
                    value1.children.forEach(function (value2) {
                        if (arrUrl[3] === value2.path) {
                            value2.expanded = 'true';
                            if (value2.selected === 'true') {
                                value2.selected = 'false';
                            }
                            else {
                                value2.selected = 'true';
                            }
                        }
                    });
                }
            });
        });
        // console.log(this.currentItems);
        /*this.menuItems.forEach((items) => {
         if (!items) {
         return;
         }
         items.forEach((item) => {
         // item.data.menu.expanded = false;
         item.data.menu.selected = false;
         if (arrUrl[1] === item.path) {
         // item.data.menu.expanded = true;
         item.data.menu.selected = true;
         this.currentItems = item;
         if (item.data.menu.expanded === false) {
         this._router.navigate([path]);
         }
         if (!item.children) {
         return;
         }
         item.children.forEach((ite) => {
         if (arrUrl[2] === ite.path) {
         ite.data.menu.expanded = true;
         ite.data.menu.selected = !(ite.data.menu.selected);
         }
         });
    
         }
         });
         });*/
    };
    MenuComponent = __decorate([
        core_1.Component({
            selector: 'app-menu',
            templateUrl: './menu.component.html',
            styleUrls: ['./menu.component.scss'],
        })
    ], MenuComponent);
    return MenuComponent;
}());
exports.MenuComponent = MenuComponent;
